package com.webviewscrolldemo.view;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class MyScrollView extends View {

	OnTouchingLetterChangedListener onTouchingLetterChangedListener;

	public MyScrollView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public MyScrollView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public MyScrollView(Context context) {
		super(context);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
	}

	private int mPosX = 0;
	private int mPosY = 0;

	private int mCurrentPosX = 0;
	private int mCurrentPosY = 0;

	@Override
	public boolean dispatchTouchEvent(MotionEvent event) {
		final int action = event.getAction();
		// final float y = event.getY();

		switch (action) {
		case MotionEvent.ACTION_DOWN:
			// Log.d("sss", "dispatchTouchEvent action:ACTION_DOWN");

			mPosX = (int) event.getX();
			mPosY = (int) event.getY();

			break;
		case MotionEvent.ACTION_MOVE:
			// Log.d("sss", "dispatchTouchEvent action:ACTION_MOVE");
			mCurrentPosX = (int) event.getX() - mPosX;
			mCurrentPosY = (int) event.getY() - mPosY;
			mPosX = (int) event.getX();
			mPosY = (int) event.getY();

			if (mCurrentPosY - mPosY > 0 && Math.abs(mCurrentPosX - mPosX) < 10) {
				Log.e("", "向下的按下位置" + mPosX + "移动位置" + mCurrentPosX);
				
				//layout(getLeft(), getTop()-mCurrentPosX, getRight(), getBottom() - mCurrentPosX);

			} else if (mCurrentPosY - mPosY < 0
					&& Math.abs(mCurrentPosX - mPosX) < 10) {
				Log.e("", "向上的按下位置" + mPosX + "移动位置" + mCurrentPosX);
				//layout(getLeft(), getTop()+mCurrentPosX, getRight(), getBottom()+mCurrentPosX);

			}
			
			break;
		case MotionEvent.ACTION_UP:
			// Log.d("sss", "dispatchTouchEvent action:ACTION_UP");

			break;
		}
		return true;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		return super.onTouchEvent(event);
	}

	public void setOnTouchingLetterChangedListener(
			OnTouchingLetterChangedListener onTouchingLetterChangedListener) {
		this.onTouchingLetterChangedListener = onTouchingLetterChangedListener;
	}

	public interface OnTouchingLetterChangedListener {
		public void onTouchingLetterChanged(String s);
	}

}
